@model Nop.Plugin.Misc.RFQ.Models.Admin.ProductSearchModel
@using Nop.Web.Areas.Admin.Models.Catalog

@{
    const string hideSearchBlockAttributeName = "RFQ.AddProduct.HideSearchBlock";
    var hideSearchBlock = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideSearchBlockAttributeName);
}

<section class="content">
    <div class="container-fluid">
        <div class="form-horizontal">
            <div class="cards-group">
                <div class="card card-default card-search">
                    <div class="card-body">
                        <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                            <div class="search-text">@T("Admin.Common.Search")</div>
                            <div class="icon-search"><i class="fas fa-search" aria-hidden="true"></i></div>
                            <div class="icon-collapse"><i class="far fa-angle-@(!hideSearchBlock ? "up" : "down")" aria-hidden="true"></i></div>
                        </div>

                        <div class="search-body @(hideSearchBlock ? "closed" : "")">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group row">
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchProductName" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-editor asp-for="SearchProductName" />
                                        </div>
                                    </div>
                                    <div class="form-group row" @(Model.AvailableCategories.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchCategoryId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SearchCategoryId" asp-items="Model.AvailableCategories" />
                                        </div>
                                    </div>
                                    <div class="form-group row" @(Model.AvailableManufacturers.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchManufacturerId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SearchManufacturerId" asp-items="Model.AvailableManufacturers" />
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchProductTypeId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SearchProductTypeId" asp-items="Model.AvailableProductTypes" />
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-8 offset-md-4">
                                            <button type="button" id="search-products" class="btn btn-primary btn-search">
                                                <i class="fas fa-search"></i>
                                                @T("Admin.Common.Search")
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card card-default">
                    <div class="card-body">
                        @await Html.PartialAsync("Table", new DataTablesModel
                        {
                            Name = "products-grid",
                            UrlRead = new DataUrl("AddNewProduct", "RfqAdmin", new RouteValueDictionary { [nameof(Model.EntityId)] = Model.EntityId }),
                            SearchButtonId = "search-products",
                            Length = Model.PageSize,
                            LengthMenu = Model.AvailablePageSizes,
                            Filters = new List<FilterParameter>
                            {
                                new(nameof(Model.SearchProductName)),
                                new(nameof(Model.SearchCategoryId)),
                                new(nameof(Model.SearchManufacturerId)),
                                new(nameof(Model.SearchProductTypeId))
                            },
                            ColumnCollection = new List<ColumnProperty>
                            {
                                new(nameof(ProductModel.Id))
                                {
                                    Title = T("Admin.Common.Select").Text,
                                    Render = new RenderCustom("renderColumnSelectProduct"),
                                    ClassName =  NopColumnClassDefaults.Button,
                                    Width = "50",
                                },
                                new(nameof(ProductModel.Name))
                                {
                                    Title = T("Plugins.Misc.RFQ.Products.AddNew.Name").Text,
                                    Width = "400"
                                },
                                new(nameof(ProductModel.Sku))
                                {
                                    Title = T("Plugins.Misc.RFQ.Products.AddNew.SKU").Text,
                                    Width = "100"
                                }
                            }
                        })

                        <script>
                            function renderColumnSelectProduct(data, type, row, meta) {
                                return '<button type="button" ' + ((row.CustomerEntersPrice || row.IsRental) ? 'disabled' : '') + ' onclick="addProductToRequest(' + row.Id + ' )" class="btn btn-default">@T("Admin.Common.Select").Text</button>';
                            }
                        </script>
                    </div>
                </div>
                <input asp-for="EntityId" type="hidden" />
            </div>
        </div>
    </div>
</section>